package com.mind.core.config;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

import org.apache.log4j.Logger;

public class CoreConfig {
	private static final Logger logger = Logger.getLogger(CoreConfig.class);
	private static final String CONFIG_FILE = "config/core.properties";
	/**  缓存中存储的玩家最大数量 */
	private int cacheMaxNum;
	/**每隔多久检查一次缓存 ：单位s*/
	private int cacheCheckPerTime=60;
	
	/**缓存中不在线玩家，保留时间（距离上一次玩家操作记录时间）：单位s*/
	private int offPlayerExistTime=600;
	private static CoreConfig config=null;
	/**
	 * 注：不用考虑同步问题，因为在服务器启动时 即会初始化
	 * 
	 * @return
	 */
	public static CoreConfig getInstance() {
		if (config == null) {
			config = new CoreConfig();
			config.init();
		}
		return config;
	}

	/**
	 * 数据库配置
	 * 
	 * @param properties
	 */
	private void init() {
		Properties properties = new Properties();
		try {
			File file=new File(ClassLoader.getSystemResource("").getPath()+CONFIG_FILE);
			properties.load(new FileInputStream(file));
		} catch (IOException e) {
			e.printStackTrace();
		}
		cacheMaxNum = Integer.parseInt((String) properties.get("cacheMaxNum"));
		cacheCheckPerTime = Integer.parseInt((String) properties.get("cacheCheckPerTime"));
		offPlayerExistTime = Integer.parseInt((String) properties.get("offPlayerExistTime"));
	}

	public int getCacheMaxNum() {
		return cacheMaxNum;
	}

	public int getCacheCheckPerTime() {
		return cacheCheckPerTime;
	}

	public int getOffPlayerExistTime() {
		return offPlayerExistTime;
	}
	
}
